package com.neuqsoft.rd.citizen.thirdapp.demo.service;

import com.google.gson.JsonObject;
import com.neuqsoft.rd.citizen.thirdapp.demo.DemoConstant;
import com.neuqsoft.rd.citizen.thirdapp.demo.dto.SweptUserDTO;
import com.neuqsoft.rd.citizen.thirdapp.sdk.UserService;
import com.neuqsoft.rd.citizen.thirdapp.sdk.dto.PersonInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Map;

/**
 * @author baidh
 * @date 2020/12/02
 */
@Service
public class Scene1Service {

    public static final String LOCAL_CITIZEN = "130300";

    @Autowired
    private UserService userService;

    public SweptUserDTO scanCode(String authCode) {
        // 2 一码通解码
        final PersonInfoDTO personInfoDTO = userService.beSwept(authCode);
        String uid = personInfoDTO.getUid();

        // 3 按需获取用户信息或身份
        final Map<String, String> userInfo = userService.userInfo(uid, Collections.singletonList("u007"));

        // 构造返回数据
        SweptUserDTO dto = new SweptUserDTO();
        dto.setUid(uid);
        dto.setIdcard(personInfoDTO.getIdcard());
        dto.setName(personInfoDTO.getName());
        dto.setLocalCitizen(LOCAL_CITIZEN.equals(userInfo.get("u007")));
        return dto;
    }
}
